<%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2021/1/27
  Time: 14:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    int visitTimes = 0;

    // 所有的 cookie
    Cookie[] cookies = request.getCookies();

    // 遍历所有的 Cookie 寻找 用户帐号信息与登录次数信息
    for(int i=0; cookies!=null&&i<cookies.length; i++){
        Cookie cookie = cookies[i];

         if("visitTimes".equals(cookie.getName())){
            visitTimes = Integer.parseInt(cookie.getValue());

        }
    }


    // 修改 Cookie，更新用户的访问次数
    Cookie visitTimesCookie = new Cookie("visitTimes", Integer.toString(++visitTimes));
    visitTimesCookie.setMaxAge(86400);
    response.addCookie(visitTimesCookie);

%>
<h1>
访问了  <%=visitTimes%>次
</h1>
</body>
</html>
